07. Binary Classification Demo

Cd13639 C1 L4 DEMO 2 V1

Using Logistic Regression to Predict Stock Market Returns

Understand how logistic regression is applied to forecasting one-day stock market returns by converting continuous returns into binary variables.

Methodology Overview:

  1. Library Importation and Setup

    • Essential libraries include function library, StandardScaler, and statsmodels API.
    • Historical stock prices are imported and converted to returns.
  2. Data Preparation

    • Convert continuous forward-looking returns into binary targets.
    • Split data into train (70%) and test (30%) sets.
    • Features derived from past returns; the target is the binary variable.
  3. Data Normalization

    • Normalize data using StandardScaler.
    • Apply scaling only to training data to avoid bias.
  4. Logistic Regression Model Creation

    • Add a constant to datasets for regression.
    • Fit the logistic regression model to the training data.
    • Observe regression output and coefficient signs.
  5. Predictive Analysis and Strategy Formation

    • Use trained model to predict returns on the test set.
    • Formulate a trading strategy based on prediction probabilities.
    • Evaluate strategy performance against the market, noting strengths like a higher Sharpe Ratio.

Explore a smoother investment strategy during down markets by leveraging logistic regression insights.